<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<link href="css/my.css" rel="stylesheet" />
		<style>
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
			}
			.mui-table-view-cell>.mui-slider-handle {
			    position: relative;
			    background-color: floralwhite;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav bc2">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">书源列表</h1>
		</header>
		<div class="mui-content mui-scroll-wrapper bc">
			<div class="mui-scroll">
				<div class="mui-card bc2">
					<div class="mui-card-content">
						<ul class="mui-table-view bc2" id="list" style="font-size: 16px;line-height: 1.5;">
						</ul>
					</div>
				</div>
			</div>
		</div>

	</body>
	<script src="js/mui.min.js"></script>
	<script src="js/config.js"></script>
	<script src="js/date.js"></script>
	<script>
		var fromType;
		var data;
		var bookId;
		var bookNumber;
		mui.init({
			
		});
		mui.plusReady(function() {
			self = plus.webview.currentWebview();
			bookId = self.bookId;
			bookNumber = self.bookNumber;
			fromType = plus.storage.getItem("fromType-" + bookId);
			if (fromType == null || fromType == "") {
				fromType = "uutxt";
			}
			getData();
		});

		function getData() {
			mui.ajax(config.config.path + "/bookFrom/list/" + bookNumber, {
					type: "GET",
					dataType: "json",
					success: function(result) {
						var code = result.code;
						if (code == 200) {
							data = result.data;
							setData();
						}
					}
				});
		}
		
		function setData(){
			var ele = document.getElementById("list");
			var html = "";
			for (j = 0, len = data.length; j < len; j++) {
				var str = '<li class="mui-table-view-cell" id="' 
					+ data[j].id + '" useable="'
					+ data[j].userable + '"'
					+ (data[j].userable == 0 ? '' : ' style="background-color:#eee"' )
					+ '>'
					+ data[j].name
					+ '<p>' + data[j].host + '</p>'
					+ (fromType == data[j].id ? '<span class="mui-badge mui-badge-danger">当前</span></li>' : '</li>');
				html = html + str;
			}
			ele.innerHTML = html;
		}

		mui("#list").on('tap', '.mui-table-view-cell', function() {
			if(fromType ==  this.getAttribute("id")){
				return;
			}
			fromType =  this.getAttribute("id");
			var useable =  this.getAttribute("useable");
			if(useable == 1){
				mui.toast("书源不可用");
				return;
			}
			plus.storage.setItem("fromType-" + bookId, fromType);
			mui.toast("切换成功");
			setData();
			var view = plus.webview.currentWebview().opener();
			//传递参数
			mui.fire(view, 'refresh', {});
		});
	</script>
</html>
